//
//  ViewController.m
//  ceshi
//
//  Created by Apple on 17/1/9.
//  Copyright © 2017年 郭凯. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
/**所有视图*/
@property (nonatomic,strong) NSMutableArray* subViews;
@end

@implementation ViewController
-(NSMutableArray *)subViews{
    if (!_subViews) {
        _subViews = [NSMutableArray arrayWithCapacity:3];
    }
    return _subViews;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    /**创建scrollerview */
    UIScrollView *scrollerView = [[UIScrollView alloc]initWithFrame:self.view.frame];
    scrollerView.bounces = NO;
    scrollerView.pagingEnabled = YES;
    [self.view addSubview:scrollerView];
    CGFloat width = self.view.bounds.size.width;
    CGFloat height =  self.view.bounds.size.height;
    for (NSInteger i = 0; i < 3; i ++ ){
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, i*height, width, height)];
        view.backgroundColor = i%2 ?[UIColor redColor] :[UIColor yellowColor];
        [scrollerView addSubview:view];
        [self.subViews addObject:view];
    }
    scrollerView.contentSize = CGSizeMake(width, height*3);
    scrollerView.contentOffset = CGPointMake(0, height);
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumLineSpacing = 0;
    flowLayout.itemSize = CGSizeMake(width, height);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"GKRoomShowView"];
    collectionView.dataSource = self;
    collectionView.delegate = self;
    [self.subViews[1] addSubview:collectionView];
}


#pragma mark - UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 2;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GKRoomShowView" forIndexPath:indexPath];
    cell.backgroundColor = indexPath.row %2==0?[UIColor redColor]:[UIColor yellowColor];
    return cell;
}

@end
